from django.shortcuts import render
from django.http import HttpResponse
from django.views import View


def index(request):
    if request.method == 'GET':
        return render(request, 'index.html')
    else:
        return HttpResponse("OK")


def home(request):
    if request.method == 'GET':
        return render(request, 'system/index.html')
    else:
        return HttpResponse("OK")


class TestClass(View):
    '''
    基于类的视图
    '''
    http_method_names = [
        "get",
        "post",
        "put",
        "patch",
        "delete",
        "head",
        "options",
        "trace",
    ]

    def get(self, request):
        return HttpResponse("这是一个get请求")

    def post(self, request):
        return HttpResponse("这是一个post请求")

    def delete(self, request):
        return HttpResponse("这是一个delete请求")

    def put(self, request):
        return HttpResponse("这是一个put请求")

    def head(self, request):
        return HttpResponse("这是一个head请求")


class BookView(View):
    '''
    基于类的视图
    '''

    def get(self, request):
        return HttpResponse(None, safe=False)

    def post(self, request):
        return HttpResponse("这是一个post请求")

    def delete(self, request):
        return HttpResponse("这是一个delete请求")

    def put(self, request):
        return HttpResponse("这是一个put请求")

    def head(self, request):
        return HttpResponse("这是一个head请求")
